<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-on</title>
</head>
<body>
    <div id="app">
        <p>
            {{}} 插值表达式，可以将vue的数据在视图中进行渲染
        </p>
        {{ msg }} 
        <h2> {{ web.title}} </h2>
        <h2> {{ web.url }}</h2>
        <h2> {{ web.number }}</h2>
        <div>
            <button v-on:click="edit">修改</button>
        </div>
        <br />
        <div>
            <button @click="edit">简写-@click</button>
        </div>
        <hr />
        Enter:  <input type="text" @keyup.enter="add(40, 60)" />
        <br />
        Space: <input type="text" @keyup.space="add(1, 3)" />
        <br />
        Tab: <input type="text" @keydown.tab="add(100, 3)" />
        <br />
        w: <input type="text" @keyup.w="add(1, 300)" />
        <br />
        <hr />
        Ctrl + Enter:  <input type="text" @keyup.ctrl.enter="add(40, 60)" />
        <br />
        Ctrl + A:  <input type="text" @keyup.ctrl.a="add(10, 10)" />
        <br />
    </div>

    <script type="module">
        // vue.global.js为传统开发方式

        // 解构赋值，将Vue里的createApp和reactive，赋值给前面的变量
        import {createApp, reactive, ref} from './js/vue.esm-browser.js'

        createApp({
            // setup选项，用于设置响应式数据和方法等 
            setup() {
                // reactive 创建响应式对象，用于存储复杂的数据类型，例如：对象、数组
                const web = reactive({
                    title: "百度",
                    url: "https://www.baidu.com",
                    number: 0
                })
                const add = (num1, num2) => {
                    web.number += num1 + num2
                }

                let count = 0;
                const edit = () => {
                    if (count % 2 == 0) {
                        web.url = "https://www.laoda.com"
                    } else {
                        web.url = "https://www.baidu.com"
                    }
                    count++;
                }

                return {
                    msg: "success",
                    web,
                    edit,
                    add
                }
            }
        }).mount("#app")
    </script>
</body>
</html>